package cate.game.play.skill.passive.fairy;

import cate.game.play.buff.Buff;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 *【制裁八方】释放后进行"善恶轮转",
 * "善"状态下每达到5层【天使羽翼】为全队恢复70%金色梦幻攻击力的生命值并净化1个负面状态
 * ,"恶"状态下每达到5层【天使羽翼】对敌方全体造成100%真实伤害，20%附加2回合的【感同身受】
 */
public class 金色梦幻灵器PH extends PassiveHandler {

	private int 善buff;

	private int 恶buff;

	private String 技能标签;

	private String buff标签;

	private int buff层数;

	private int 善技能;

	private int 恶技能;

	//善buff=？？&恶buff=？？&
	//技能标签=制裁八方&buff标签=天使羽翼
	// &buff层数=5&善技能=？？&恶技能=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		善buff = args.getInt("善buff", 0);
		恶buff = args.getInt("恶buff", 0);
		技能标签 = args.get("技能标签");
		buff标签 = args.get("buff标签");
		buff层数 = args.getInt("buff层数", 5);
		善技能 = args.getInt("善技能", 0);
		恶技能 = args.getInt("恶技能", 0);
	}

	//当前的状态
	private boolean good;

	@Override
	public void onFirstEnter(ActionCtx action) {
		setGood(action,true);
	}

	private void setGood(ActionCtx action,boolean good){
		this.good = good;
		if(this.good){
			skill.owner.buff.tryAddByTid(action, 善buff);
			skill.owner.buff.removeBuffByTid(action, 恶buff);
		}else {
			skill.owner.buff.tryAddByTid(action, 恶buff);
			skill.owner.buff.removeBuffByTid(action, 善buff);
		}
	}

	@Override
	public void onOwnerMoveDone(MoveCtx move, TimeActionCtx action) {
		if (move.getSkill().cfg.containTag(技能标签)) {
			setGood(action, !good);
		}
	}

	@Override
	public void onOwnerAddBuff(ActionCtx action, Buff addBuff) {
		if (buff层数 <= 0) {
			return;
		}
		if (!addBuff.cfg.containTag(buff标签)) {
			return;
		}
		int buffNum = skill.owner.buff.countBuffByTag(buff标签);
		if (buffNum % buff层数 != 0) {
			return;
		}
		int appendTid = good ? 善技能 : 恶技能;
		Skill appendSkill = action.getCfg().skill.buildById(this.skill.owner, appendTid);
		if (appendSkill == null) {
			return;
		}
		if (action instanceof SkillActionCtx) {
			((SkillActionCtx) action).getTurn().addAppend(new AppendMove(skill.owner, appendSkill));
		}
	}
}
